performance improvement and bug fixes