added log debug
Cleaned up a bit and added better uniqueness constraints (per series) and duplicate handling.