UPDATE: Complete rewrite of the code. It's not pretty, but so far it works. Uses only two if statements. $v1 and $v2 appear to be working correctly thus far, unless used within the identifier. Thanks to SReject for helping on #msl. I have yet to test everything jaytea's mentioned.