Refactored problems 16 to 20