Possible fix for while loop not being called