less naive implementation looks ok