Moved widget drawing code to its own class