more work on the less naive implementation