Refactored some code in widgets