mass refactoring, fixing and cleaning