slight reordering of functions