base code for reading file