improved the write method and added a test.py file to illustrate some of the changes.