bug fixes and performance improvement