working but needs debugging