Added ability to change 'logger' (i.e. to winston) and improved error handling