Bug fixes and other improvements