fixing some minor bugs introduced in the last refactoring. fixing a lot of jslint errors