Done a LOT of code abstraction, cleaned up a lot and added more
functions to the db.