updating script for data cleanup with more logic