fixing stale cursor error