Fix line endings, lazy cache the database connections, use a dedicated template parameter instead of a hack that assumes there is a template variable