fixes and new learning algorithm