Simplify the code for fragment-detection