Started code refactoring before merging to master.