Third batch of major code cleanup