Solved more problems, refractored a bit

Solved problems 18 and 67 (basically the same problems with different
numbers).
Did some refractoring to make the code easier to read.