Minor refactoring
Change some functions to be ref. transparent
Add doc