Performance Optimizations

Loops should be faster, and changed a couple of multiple condition if statements to use the 'in' operator on a predefined object.

A few other code cleanup changes as well.