Refactor problems 1 to 4