fixed errors, improved performance