add type assertion and refactor defined