fix random() and cleanup while here