New API module and support for pings and better connection closing