Added proper (i hope) support for reference parameters and eliminated extra copies. Note that there are quite a few extraneous moves still.