Peter's changes

Added changes from peters code
and edited them to compile properly