fixed the write method