Checked that the outputs are correct for sample data 2