Implemented lock inside of the loop.

- This successfully prevented there from being duplicate state changes
 (i.e. sending signaals of True, True, True...
- However, with the 10k locked simulator the behavior is still erratic
- Therefore this change should be made no matter what, but we should also make the locking block