unify global variables
bug fix
implement safe randomizer