added flash messages and sorting