Adapted tutorial.