WIP refactoring, cleanup & documenting