some refactoring issues, add flash error