Fixed tests
Fixed bugs in algorithm
Added model tests