Added exit handler for logout commands (ctrl+d, 2xctrl+c)

Fixes #594