Refactored problems 41 to 45