refactored problems 3 & 4