simplified code in one of the slides