Fixed nesting bug with message loop