Minor refactoring and api docs