major cleanup and refinements