refactored the target setting code