major refactoring, cleaning the code