New algorithm seems to work. But still needs test.

Will have to work on the delete feature and database setup. So branch
first.