Cleaning up badly designed code