fix 500 error when tables are empty