refactor and add some code