Autorefresh logic improvements

When switching between examples, and autorefresh is off, reload the
code. Also reload when ticking autorefresh on.