Add Makefile, some refactoring