Add login error msg and refactor