working, needs sql rework