refactor and remove old code