Fixed a couple bugs in the learning algorithm