Cleaned up code and fixed widget loading event.