add Makefile and optimize some code