MySQL changed to MySQLi and bug fixes