Substantially modified begin-middle-end.js.  Currently it's broken.