restructure and fix Makefiles