main spaghetti code
little changes to jshint
refactor with module pattern