More debugging of data writing error

Plus small tweaks to other files