Refactor and remove memory leaks
Refactor Makefile