refactored compareVar into a simpler function and helper function.