Randomized choices and did some refactoring