Improve command completion code