Cleaned up code somewhat. JSHint and js-beautify done.