add write() function to simply the code and comment