major cleanup and simplification