just fixed a couple of things - agrees with matlab