simplify the code according to Paul's comment