Refactored beam() routine a bit.