added support for smart grid
fixed grid behaviour
merged master with grid_v1 branch