update,fix some algorithms, make better tests