Huge Revamp

Revamped the code throughout.

If there is no match between data then we just add what we can. The
matching algorithm can be improved in the future but it works fine for
now.