made some changes and added flash messages