Lots of added functionality and refactoring.