Fixed bugs on ALGORITHM!
add test cases