created seperate function for error