Implemented conditional cleanup