code cleanup, minor changes such as invert if statements