Fixing various issues with edges. fixes #2340 #2339 #2330 #2331
(cherry picked from commit f53dc5c9d1b2bfbb794649133ba9205a09edb390)