Refactoring and implementation WIP