massive cleanup and documentation