Moved db stuff to a class