WIP started refactoring

WORK IN PROGRESS