Added proper handling of 404 errors