Rearranged the state locks to try and improve the performance.  Removed the locks from led.py and database.py.