Added changes to rand and cleaned a little.