initial  commit of real code. needs a bit more tidying up