Clean up library code with function hoisting.
We now have the public APIs and synchronous methods first everywhere.

What's not so nice is having two different nested functions to create a fitting refresh queue.
I can't think of a nice function that would handle both cases well right now, but with some more
engineering and thinking it should be possible.