Adds main refactoring and already right output. Still missing documentation and unit testing.