Refactors test to avoid potential undefined behaviour