add extension classes and refactor code