Major changes: Recoded for MySQLi