Bug fixes and performance improvement