Merge in new detection code