Finished refactoring and documentation