refactoring the swiping functionality