Maybe fixed invokeandwait to work properly.