Refactored, added randomness