refactor and check for duplicate file pointer locations