Better line reading

It should be less prone to DoS by memory exhaustion.