Implement flexible target specification

See commit message.
Reverted by accident?