begin to refactor grid functions

unknown compile status