need to refactor and resolve logic