Added commenting and made the data trasnmission into its own function