LoopFix

Fixed possible infinite loop as per Kevin's suggestion