Fixed a critical bug in learning algorithm.