Several improvements

- solve jshint problems
- start tests
- improve error handling