Clean up WorkflowDefinitionResource code and add more tests for corner cases