refactor ConnectionStateHandler - make it more understandable