Make .shutdown work if renderer was not created

Fixes #486
Fix some flake8 errors
Use a copy of segment dictionary to avoid modifications

Modifications are done below when adding 'before' and 'after' keys to text. You
will see problems only for non-function segments
Make sure nothing in Theme modifies segments
Add basic rendering tests