rewrote scrubbing code