uglify and a lot of refactoring