refactor. refine type checking.