working on problem3; more readable