Update code as suggested by the great @DavidBruant