added function to check for invalid coordinates