improve flush behaviour and tests