Made command dispatching more thread-safe