refactor to use magma/lava api