Fix when, add tests, jshint