refactor and remove unnecessary code