added random function and several fixes