some code improvements made during class - need to revisit