Improved the makefile

Changed the mechanism for automatic dependency generation.
Added rudimentary regression testing.
Restructured and added comments.