Merged codes from Brian for GUI submission.