Mesh untangling and smoothing is an important part of the meshing process to obtain high-quality discretizations. The usual approach consists on moving the position of the interior nodes while considering fixed the position of the boundary ones. However, the boundary nodes may constrain the quality of the whole mesh, and high-quality elements may not be generated. Specifically, thin regions in the geometry or special configurations of the boundary edges may induce low-quality elements. To overcome this drawback, we present a smoothing and untangling procedure that moves the interior nodes as well as the boundary ones, via an optimization process. The objective function is defined as a regularized distortion of the elements, and takes the nodal Cartesian coordinates as input arguments. When dealing with surface and edge nodes, the objective function uses the nodal parametric coordinates in order to avoid projecting them to the boundary. The novelty of the approach is that we consider a single target objective function (mesh distortion) where all the nodes, except the vertex nodes, are free to move on the corresponding CAD entity. Although the objective function is defined globally, for implementation purposes we propose to perform a node-by-node process. To minimize the objective function, we consider a block iterated non-linear Gauss-Seidel method using a hierarchical approach. That is, we first smooth the edge nodes, then the face nodes, and finally the inner nodes. This process is iterated using a node-by-node Gauss-Seidel approach until convergence is achieved