added isOnEdge function for edge detection error
resulting in endless loop