Refactor makefiles