Minor: why do you use std::flush after std::endl? (I thought that std::endl always flushes the output buffer)