complete rewrite
added correlation code from 3rd party