problem 10

some minor pruning for optimization