Bug fixes and improved performance