refactored and commented touch code