working generic version of chainer