Go performance improvment by @lionkov.