500 Internal Server Error and some refactoring
Implement flash messages