Update brim generation code. Includes regression test. #1440