fix a lot of bugs
add a debug make option to Makefile
add test scripts