Major code cleanup and refactoring; Makefile added