Lots of new functionality and cleanup