added code for homework 4, not tested