split out readheader function