validations, DOM cleanup and general refactoring