Refactored code under top level if statements