Implement flexible target specification

See commit message.
Ah nevermind, I remember what this is doing now. No worries!