refactor command thread