Implemented midNode function