improving grid module
split grid module (put unsafe funciton appart)