made a function for sending the data and some other minor changes