misc code cleanup, including rearranging some args