refactor of puzzlecode