Found a more elegant fix from the previous commit's bug