fixed received pointers and small rewrite