hw2 code reorganized; problem 2 seems to work