Major cleanup of the CPS code (but more is still to come)