moved randomize() in a more proper place