added config file and some error handling