Fixed the edge conditions