OK, I "acquired" this code from flush.py - I'll attempt a refactor on this.