Refactored to take target into account