Learning algorithms, need some debugging