Implemented end connection. Not sure if it works.