fixed several naive performance bugs