Adding some docs and minor refactoring.