Refactored getTarget and validTargetLoc.