refactor to get rid of if statement