Reorder some things in the source code to match the sample source definition order. Add and remove some TODOs.