Task stack fixes

Various changes to the task stack handling.