Fix table filling algorithm