slight optimization using if bools in a function