refactor solution to X/O count problem