Fixed scanner not being closed, made infinite loops nicer.