Tidy up configuration and add error handling