added more logic to grid