Implement writeField function