fixed deriv NSRef, tested some loops