Refactor: major refactoring, there should be no unused code and doublicate functions.