GSOC changes by Paul

Large changes from Paul's GSOC work.