finalized CW trends code