Clone task feature from Badi.

This pull request is the same as #425 except it cherry-picks the commits in there.