refactor assign fn