fixed infinite loop situation / added test