Move flushing to a function

Allows using manually to flush rewrites. This is handy if you want to add
extra features (such as locking) but still use the hooks and better
flushing system.