Bugfix lock

Moved coded inside handler as tabs.query is asynchronous.