Reusing some parts from Hazou.