mlubin's stagedfunction fixes

Looking really good!

@mlubin, I credited you as author of the key commit.