refactor data sending code into common method