Change function order to improve refresh behavior