Fix bug in write. Still need to verify write system call.