Added Makefile.
Added test target.
Fixed some bugs.