Modified algorithm, added more randomness