Broke large function into smaller ones and updated to handle arbitrary 'BoardSize'.