fix bugs and add algorithms