Combined my javascript and refactored some stuff to appease Douglas Crockford