a few iterations and optimizations for problem 10