Improved Makefile and fixed bugs