The main work for flooding the grid plus commented the code