Changed code to fit assignment needs