fix some errors
change detection routine
fix some errors