Reorganized class relations and removed c-style casts.