Refactor svg generation

This is just to help me understand the code, really!

Still seems to do the job, as far as I can tell `:)`

@Ian-Foote Feel like having a quick look?