Last version from Jaime (before switching from fortran to numba.jit and before removing pydantic)