modulize and added file number detection