Remove unused var and messy assignment+comparisons