Fix range error, still poor performance