Updated the code to compare coordinates