Bug fixes and simplification