Final code to match demo script