handles: fixed infinite loop (thanks @dmikis)