apply method. example. extended example + new comments added.