Improve edge detection so returned cells end up on actual edges