Added error handling to resolve #2