a working but really slow version