major cleanup of the code