re-applied some code changes lost recently