Changed to use arrays for nodes and grid for quicker access and cleaner code