clean up write, and add support for address