Bug fixes

Results of the valgrind check