Refactored problems 3 and 20. Changing structure of main to be more elegant