Suggestions from code review

I've made eight small commits so you can see each suggestion individually with an explanation. Note in particularly the extended suggestion on the eighth commit - not in the code - for a further possible cleanup.

I think the `get-api` function could be simplified to make it easier to read and explain but I'm not sure which way to slice and dice it at the moment.

We can discuss individual suggestions further on the commits themselves by adding notes to a particular line.