fix for an infinite loop condition