Fix clear messages function