Updates to writing, lots of debug output