refined code, Part 1 works