Simplify the code using bool variables