Divide code

First steps in refactoring