Neatened ifs, separated output streams, added flags.