Fix discarding bug and fixed a login problem