Rewrote changes from Brian 1 + minor changes