changed var grid to global variable