introduced proper error handling