add login support, fix some bugs