Rough code, correct solution