add solution to puzzle 04 plus some refactoring and bug fixing