Start of the refactoring. Commit is quite big because I forgot to use git right from the beginning. Sorry.