Major refactoring/documentation