Clean up

Many changes including the deletion of unused code, documentation fixes and fixing compiler warnings.