Added centralised mysql connection.
Urgent bugfixes.