update code to refactor, pending to fix code