Eliminated unused variable.
Reduced length of long method.
More function simplification, plus addition of test.