refactor and add test classes.