refactor, add hg support