Fix image writing, implement reading. Almost working.