Refactor if statement for scope variable