Move create_new_db code to separate function