refactor code to check for touch