code from first half