Added flash messages and some other refactoring