refactor for unit testing and change auton