Updated Mari's code