Implemented merging and closed edges