Fixed a bug with flushing the files the correct way
Mega commit
More fixes