Some refinement/refactoring and documentation