Bug fixes, makefile, and test cases