fewer calls to len() in go version