Fixed infinite loop of the Learn() function