Don't auto-refresh the preview iframe if no activity has taken place since the last refresh.

Also, code reorganization.