Refactor to reduce cyclomatic and boolean complexity issues