Initial Go code for reimplementation