Merged with Rawand's stuff

Now contains all code so far, some outstanding bugs for Rawand to fix