Some fixes to detection