fixed wrong direction when swiping, some code cleanup