fixed dennis' code, now it works