Minor style cleanups, pulled database connection into its own function