Fix & tests for https://jira.int.corefiling.com/browse/REVIKI-566
The code is simpler too :)