cube implementation