replace conditionals and refactor