Rewrite NBT writer to be a bit cleaner