Rewritten from scratch and compatible with genesis 2.0