Fix buffer overrun bug, and correctly allow flushing during construction