Added Matthew's code for comparison and integration