fixed a number of bugs with pointers etc.