Fixed an infinite loop