dynamic grid working
pulling functions out of nested function