code written to solve hw problems for week 4
simple modifications