LPS-37352 - Refactored to be more easily understood; added boundary tests