This commit moves a huge chunk of the code to go. The TODO.md document indicates what is left to be done.