middle-out implementation

See bottom-up implementation.