Resync with npol's code.