fix all algorithm bugs
fix bugs and add new feature