Added missing header files.
Fixed valgrind errors.

This error was fixed before, but now I've removed the unnecessary function and
lines.