modified copy to use thrust function