first cut, appears to work, need to add more comments