minor changes + formatting
updated to ensure reading files are closed and that link_hdr() is used when appropriate