Refactor setElement