Redundant check here since you check formats.length on the next line