Tidying up

- linted (javascript lint and jslint)
- removed unused code
- removed global references