Fix the slowliness of the authentication process and rewrite some code