Cleaned up some code and made it work more like a widget.