Implemented some kind of apparently working write wrapper.