Add Makefile to facilitate IDE
Fix up some old bugs