tidied things up a bit and ran it against jshint