Added error handling (404 and general errors)