reorganized code from code.google, 1st unit test passing