Improve code readability by flattening logic tree