refactor some code to type_service.js