moving  logic out of Thor