small modifications to grid operations
fixed synchronization problem between grid initialization and code generator