Add keepalive handler and better error handling
Merge changes