First working version. Still problems with unique constraints and
differences.