runs good but with valgrind illegal read, segment fault end