cleanup reconnect conditional and improve code readability