refactor so that instDir can be invoked as an API