Add mercurial support and do some cleanup