Credit @dyn888 for improving format selection