updated as per Homework 4