Fixes error with multiple targets

If using multiple targets, the following error could occur: "A task's completion callback has fired
when the task was already in a completed state"

The PR also builds on @ahdinosaur's pull request #6.