refactor and remove unused functions