Rewrite and optimize all the brick program.