Fixes problems found when assertion is enabled