bug fix. rand function also updated, so can be updated easily in future