Jshint code style

In an attempt to make the code more consistent and hopefully more bug free I integrated jshint, and fixed some RegEx bug.