working (slow) implementation