major refactor, mostly to bring in flushing