Improve clean-up logic