Several fixes and improved performance