Fixed algorithm.
Fixed test file.