added support for auto-detecting the format