refactor cell creation function. working version