refactor code for cmd queue