refactor and remove unused code