Fix corner-finding routine