A number of bug fixes and small improvements