separated model from widgets and tidied code