more refactoring and updated docs