Clean up login code, and add reporting of flash errors