refactored the clean logic