Bugfixes and made learning.py cleaner