Refactored some communication code