issue #18 infinite looping fixed