extracted wordfile detection code to function