more test refactoring.
refactored database RunCommand.
added sort support.