Added proper handling of Monitor.Exit() and reset of taken locks. State0 is now a special case because it doesn't need to release a previous lock