Refactor if statement out