refactor some code api and management code