first version, still some bugs, probably dead pointer