Several fixes (thx Sachin Thomas)