some fixes

collection of local patches
Where does that var come from?