fix endless loop

Thanks to Robert Huitl (see #18)