Revised beams functionality using the addChildBefore function