Fixes and performance improvement