Do more code cleanup
Fix a bug with page write that will cause some data to be lost
Make internal helper fumctions private