added tests for scenario support. moved some logic to make code more testable