Fix code structure, add flash message.