fixed bug with wrong edge-checking