fixed up messy logic for cleanup method