Fix for finish event firing multiple times. Fix #242.

The fix is based on the answer from the stackoverflow link I posted on #242.