Bug fixes and simplifications