Massive cleanup of the rpt code, updating to current coding guidelines