Fixed a bug and utilized randomness.