Added error handling and explicig configuration passing