Made a few easy optimizations on problem 5.