Slight refactor. Add doc comments.