Refactored user api and fixed some bugs.