refactoring switchDirection