refactoring for 1st official release.   just need to add some comments and get rid of warnings.