modify code according to Paul's review