various improvements. valgrind checked at 0/0