Added array size check in write method.