Rework the order of functions.
  Added TODO: functions I think we need.

  More will be required, but these are sane enough and we'll
 certainly need them.