This function takes a $data array