Fixed code as per instructor and added comments