clip extraction code