moved config; fixed error-handling