adjusting logic to match latest changes