correction for infinite loop when out of memory

see issue #3 on github