Now detects and appends file extensions properly