use original makefile and some refactoring