Final working commit - still fairly rough but same code as submitted in version 1.0