Fixed bugs in algorithms