improved edge selection function