Turning this code into a widget