moved check for frag defined to top of method