Simplify pending/timeout-finding lua code