improved grid angle and length detection