Bug fix and performance tune