write helper function