Simplify logic and clarify variable names