Consolidated code to reduce size.
Also fixed multi-flushing of dirty block (maybe needs more)