Multiple bug and code fixes ,final copy00