Magma code as written by me (Maarten Derickx)