Implementation is mostly based on Sergey Levine work (http://www.eecs.berkeley.edu/~svlevine/).