add target check and refactor