Refactor terminating on gen_server and ws_handler