Code cleanup, especially for RunMultiKeyThread