Modularized layout code, fixed jshint warnings