tentatively working version of beam learn, other various cleanups