implemented your suggestions, tested working on ST2

I also had to remove the `encoding` keyword from the write method