more refactoring/tidying/documentation