minor optimizations and fixing jshint warnings