Purge old code, refactoring and documentation