Merging code from Ouliana.  Cleanup, bug fixes to come