Added better handling for flash messages