Code fixes

The last update broke the MySQL connection sometimes. Should be fixed
now.