add a base dir, refactor code for extension