refactor some code, remove unused code