fixed to handle varying file extensions