rewrite algorithm
modify some test