reduced complexity of cleanup code