implementing code for command completion.
Refactoring command completion.