Move write() to module, closes #18.