Updated plotting and simulationg code for arbitrary S