First refactoring steps

*WORK IN PROGRESS*