Moved DB functions to class

Now with DB transactions!
Checks for cached URL hash before saving to prevent collisions