Bases of T-meshes and the refinement of hierarchical B-splines