Style cleanup and fix a possible endless loop