rewrite for better testing.  code now broken