refactor some of the code