Wrote Main program for testing. Minor bugfixes.