Refactor assign user code