refactoring swipe logic to make more readable