Solve puzzle 3
More code refactoring. Get rid of global variables in code.
Puzzle3 now runs without errors.