moved check block to correct part of function