more work with pseudocode, too incomplete to test