refactor + enhancing fourth puzzle