Initial conversion from python to Go.