refactored and 2nd attemp for swipe function