various improvements. valgrind checked at 0/0
various improvements. valgrind checked at 0/0