Fixed many bugs and improved performance in learn_period_management