Fixed missing spaces in template.
Moved the connection to db to a separate module