updated to be able to use .write method