simplify logic in a small block of code