Various fixes and simplifications