ermegherd I left this in a terrible state last time. this is clean up