modularize brain plot code