Ported over some blocks from IaS1.