added some debug flags to makefile and fixed a few memory leaks.