fixed performance/correctness issues in stdlib