added --cleanup mode, added some error messages