Changed the algorithm, added additional, more complex tests.