Updated the get_coordinates function with more sensible error handling