This is hard to read and I think we need some kind of similar condition in the if (DOUBLE) block. I'll pull this in and try to simplify it a bit.