Added bufio-based output for speed.