Revised code for second table