Added test for rendering
Moved the bulk of the renderer to its own function
Now buffers up rendered parts and then joins them at the end
More refactoring and introduced state.derive for creating child states