Moved check out of loop