rearrange code so exported APIs are at the top