a working, slow implementation