Fixed memory leaks

Two fixes for problems that caused memory leaks:
- Converted implicitly created global variables and functions to local variables.
- The touch events on the document needed to be unbound on directive destruction