Added a check on missing content-type header
Rearranged code to make modular
fixed example due to rearranging code
Added jshint rules, fixed some violations