Reworked neighborCount function