added code to save output widget state, needs testing; some style tweaks