Using -fbounds-check revealed some minor bugs