removed bugs and improved performance