added auto detect for file extension