Test refactoring, API extended to support timeouts and trials