Fixed running commands in threads