implemented endianess checks in write function