Reading regsiters first - the updating the database
Correct global variable issue