finished lab5 code