Made write() work for 16-bit as well