Makefile fix + refactoring