More cleanups, better doc, little refactoring