A lot of refactoring and todo cleaning