Fixing an infinite loop and indentation problem