refactor common code and fix deps issue