Best time to buy and sell stock III - refactoring