reworked cleanup sequence