Fix mask output, allow selecting output format.