Change the implementation of the previous bug fix

Slightly less error prone than the last fix