Refacted the api-related code, login and register finished