a slightly better version, but still two unfixed bugs