fix some bugs related to compact()

Hey, just a heads up - I do not know what I'm doing here...
But the changes that I've added made the failing test cases work.

This is just a first commit, I'll take a closer look later to see if the changes I've done got some sideeffects. And get some more tests written.
This may get through the test temporarily, but it will fail at some point.  Multiple readable files exist when the number of entries stored increases.