Tidied up MongoDB interface and added template parsing for config file