Started using flat sets for better performance
Added a more efficient neighbour check