Simplified the code for flash messages