Fixing closure bug in tasks