cleaning up ancient code I barely understand anymore