Wrap everything in function & fix jshint warnings