Fix various bugs working towards factorial