hierarchy refactored and sum added