Improved performance and bug fix