Refactored the code by adding a Communications class.