Improve barcode formatter speed, add tests for it

Should also fix #411.