Am I to understand from your explanation that they asked you to solve a real business problem with real business data as an unpaid "coding test"?
If so, I'd say they were clearly in the (legal) wrong even before asking for the refined version.
If so, I'd say they were clearly in the (legal) wrong even before asking for the refined version.