problems 13 and 14, minor refactoring