More formatter work.

Implement functions, add test.

Functions don't hugely need to be optional, we can just carry on
if the function is invalid.