Re-added code from 9e5be13
Merge pull request #85 from alex-gh/thunk_fix2

Re-added code from 9e5be13