code clean-up: introduced some logic in communication