improved coordinate detection