Moved db implementation to separate file