CG HW5: helper codes added.