Function for handling data