Catch errors better
Update for new MySQL database layout