bugfixes and jshint compliant