Homework -- finally got it working