Fixed bugs in the doneFunction code; fixes #229

Bug fix related to issue: #229