Added error handling to services function.