Tidy up and do flushing more correctly.