Moved table creation to a separate function

The logic for creating tables for the database has been moved to its own
function to make the code more functional. The code in the function does
not use with-db-connection so that the caller is not forced into
interfacing with the database in that fashion.