refactor intern function
rearrange ordering of functions