Added touch support and refactored the code.