Bugfixs, refactoring, documentation