Fixed bugs and improved performance