Clean up measure implementation, and add an improved test case.