Fixed problems with touch devices; Small refactoring.