massive rework and refactoring