refactoring, added makefile, some speed improvements