Updated to eliminate compiler errors and warnings
Updated to fix valgrind errors