Almost working variant. Fixed DB bug